package socket;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * Created by zzy on 2018/1/9.
 */
public class InetAddressTest {
    public static void main(String[] args) {
        try {
            InetAddress inetAddress= InetAddress.getLocalHost();
            System.out.println("计算机名："+inetAddress.getHostName());
            System.out.println("IP地址："+inetAddress.getHostAddress());
            byte[] bytes= inetAddress.getAddress();
            System.out.println("IP地址字节数组："+ Arrays.toString(bytes));
            System.out.println(inetAddress);
            String phoneIp="192.168.1.105";
            InetAddress phone= InetAddress.getByName(phoneIp);
            System.out.println(phone.getCanonicalHostName());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
